package com.dameng.parallel;

import org.testng.annotations.Test;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 测试方法调用的并发线程数量
 */
public class MethodParallelTest {


    /**
     *  invocationCount应该调用此方法的次数
     *  threadPoolSize = 5,invocationCount=1配合使用
     *  threadPoolSize 只对 invocationCount 有效，对@DataProvider无效
     * @throws InterruptedException
     */
    @Test(threadPoolSize = 3, invocationCount = 9, timeOut = 10000)
    public void testWithThreadPool() throws InterruptedException {
        Thread.sleep(500); // 模拟业务逻辑
        System.out.printf("执行时间: %s | 线程: %s%n",
                new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()),
                Thread.currentThread().getName());
    }
}
